//
//  BLMainViewController.m
//  BiologyLibrary
//
//  Created by milo on 16/7/1.
//  Copyright © 2016年 youxh. All rights reserved.
//

#import "BLMainViewController.h"
#import "CVSegmentedControl.h"
#import "RecordFirstViewController.h"
#import "CustomNavigationController.h"
#import "Record.h"
#import "SearchFirstViewController.h"


@interface BLMainViewController ()

@end

@implementation BLMainViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self hideNaviBar:YES];
    UIView*topview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 64)];
    topview.backgroundColor=[UIColor colorWithRed:0.19 green:0.22 blue:0.27 alpha:1.0];
    [self.view addSubview:topview];
    
    UIButton *leftbtn = [UIButton buttonWithType:0];
    leftbtn.frame = CGRectMake(10+10, 30, 30, 30.0);
    leftbtn.backgroundColor = [UIColor clearColor];
    [leftbtn setImage:[UIImage imageNamed:@"userhead_temp"] forState:UIControlStateNormal];
    leftbtn.layer.cornerRadius = 3;
    [leftbtn addTarget:self
                action:@selector(showleftview:)
         forControlEvents:UIControlEventTouchUpInside];
    [topview addSubview:leftbtn];
    
    UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 35, 5, 20)];
    img.backgroundColor=[UIColor clearColor];
    img.image=[UIImage imageNamed:@"mianleftbtn"];
    [topview addSubview:img];
    
    btn1 = [UIButton buttonWithType:0];
    btn1.frame = CGRectMake(fWidth_Current/2-70, 10+20, 70, 30);
    btn1.backgroundColor = [UIColor clearColor];
    btn1.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btn1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];

    [btn1 setTitle:@"记 录" forState:UIControlStateNormal];
    [btn1 addTarget:self
             action:@selector(showrecorde:)
      forControlEvents:UIControlEventTouchUpInside];
    [topview addSubview:btn1];
    btn1.selected=YES;
    type=@"record";
    line1=[[UIImageView alloc]initWithFrame:CGRectMake(btn1.frame.origin.x+5, btn1.frame.origin.y+30, 60, 2)];
    line1.backgroundColor=[UIColor whiteColor];
    [topview addSubview:line1];
    btn2 = [UIButton buttonWithType:0];
    btn2.frame = CGRectMake(fWidth_Current/2, 10+20, 70, 30);
    btn2.backgroundColor = [UIColor clearColor];
    btn2.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btn2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [btn2 setTitle:@"查 询" forState:UIControlStateNormal];
    [btn2 addTarget:self
             action:@selector(showsearched:)
   forControlEvents:UIControlEventTouchUpInside];
    [topview addSubview:btn2];
    line2=[[UIImageView alloc]initWithFrame:CGRectMake(btn2.frame.origin.x+5, btn2.frame.origin.y+30, 60, 2)];
    line2.backgroundColor=[UIColor whiteColor];
    [topview addSubview:line2];
    line2.hidden=YES;
    
    _typeArray = [NSArray arrayWithObjects:
                  [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithInteger:TYPE_RECORD_XUEYANGBEN], @"type",
                   [NSNumber numberWithInteger:6], @"allStepCount",
                   @"血样本收集", @"record", @"血样本查询",@"search", nil],
                  [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithInteger:TYPE_RECORD_SHITIZHONGNIU], @"type",
                   [NSNumber numberWithInteger:9], @"allStepCount",
                   @"实性肿瘤组织样本收集", @"record", @"实性肿瘤组织查询",@"search", nil],
                  [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithInteger:TYPE_RECORD_NANGXINGZHONGNIU], @"type",
                   [NSNumber numberWithInteger:14], @"allStepCount",
                   @"囊性肿瘤样本收集", @"record", @"囊性肿瘤样本查询",@"search", nil],
                  [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithInteger:TYPE_RECORD_XUEJIANGYANGBEN], @"type",
                   [NSNumber numberWithInteger:7], @"allStepCount",
                   @"血浆样本分离", @"record", @"血浆样本分离查询",@"search", nil],
                  [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithInteger:TYPE_RECORD_XUEQINGYANGBEN], @"type",
                   [NSNumber numberWithInteger:8], @"allStepCount",
                   @"血清样本分离", @"record", @"血清样本分离查询",@"search", nil],
                  nil];

    
    Maintableview=[[UITableView alloc]initWithFrame:CGRectMake(10, 64, fWidth_Current-20, fHeight_Current-64)];
    Maintableview.backgroundColor = [UIColor clearColor];
    Maintableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    Maintableview.dataSource = self;
    Maintableview.delegate = self;
    [self.view addSubview:Maintableview];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return [_typeArray count];//返回标题数组中元素的个数来确定分区的个数
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 55;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, fWidth_Current, 18)];
    headview.backgroundColor=[UIColor clearColor];
    return headview;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *strIdentifier = [NSString stringWithFormat:@"strIdentifier%ld",(long)indexPath.section];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIdentifier];
  
    NSDictionary *tempDict = [_typeArray objectAtIndex:indexPath.section];

    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:strIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.backgroundColor=[UIColor colorWithRed:0.16 green:0.19 blue:0.24 alpha:1.0];
        
        UIImageView*userheadview=[[UIImageView alloc]initWithFrame:CGRectMake(13, 10, 35, 35)];
        userheadview.backgroundColor=[UIColor clearColor];
        [cell addSubview:userheadview];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        
        _typeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, fWidth_Current-100, 55)];
        _typeNameLabel.textColor = [UIColor whiteColor];
        _typeNameLabel.tag = g_iTag_Label;
        [cell addSubview:_typeNameLabel];
        
        switch (indexPath.section) {
            case 0:
                
                [userheadview setImage:[UIImage imageNamed:@"maintip1"]];
                
                break;
            case 1:
                
                [userheadview setImage:[UIImage imageNamed:@"maintip2"]];
                
                break;
            case 2:
                
                [userheadview setImage:[UIImage imageNamed:@"maintip3"]];
                
                break;
            case 3:
                
                [userheadview setImage:[UIImage imageNamed:@"maintip4"]];
                
                break;
            case 4:
                
                [userheadview setImage:[UIImage imageNamed:@"maintip5"]];
                
                break;
                
            default:
                break;
        }
    }
    
    _typeNameLabel = [cell viewWithTag:g_iTag_Label];
    _typeNameLabel.text= [tempDict objectForKey:type];

    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *tempDict = [_typeArray objectAtIndex:indexPath.section];
    
        if ([type isEqualToString:@"record"]) {
            RecordFirstViewController*RecordFirstVC=[[RecordFirstViewController alloc]init];
            RecordFirstVC.recordName = [tempDict objectForKey:type];
            RecordFirstVC.recordType = [(NSNumber *)[tempDict objectForKey:@"type"] integerValue];
            RecordFirstVC.allStepCount = [(NSNumber *)[tempDict objectForKey:@"allStepCount"] integerValue];
            [self.navigationController pushViewController:RecordFirstVC animated:YES];
            
            
            
        }else{
            
            SearchFirstViewController *searchFirstVC = [[SearchFirstViewController alloc] init];
            searchFirstVC.recordName = [tempDict objectForKey:type];
            searchFirstVC.recordType = [(NSNumber *)[tempDict objectForKey:@"type"] integerValue];
            searchFirstVC.allStepCount = [(NSNumber *)[tempDict objectForKey:@"allStepCount"] integerValue];
            [self.navigationController pushViewController:searchFirstVC animated:YES];
        }
    

}

-(void)showrecorde:(UIButton *)sender{
    if (sender.selected==YES) {
        return;
    }
    sender.selected=YES;
    btn2.selected=NO;
    line1.hidden=NO;
    line2.hidden=YES;
    type=@"record";
    [Maintableview reloadData];
    
}
-(void)showsearched:(UIButton *)sender{
    if (sender.selected==YES) {
        return;
    }
    sender.selected=YES;
    btn1.selected=NO;
    line2.hidden=NO;
    line1.hidden=YES;
    type=@"search";
    [Maintableview reloadData];

    
}
- (void)showleftview:(id)sender
{
    [self.sideMenuViewController presentLeftMenuViewController];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
